﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Global.Class.Library;

namespace DataTransferObject
{
    public class GCGBCommandCollection : NotifyPropertyChangeObject
    {

        private int materialSetID;
        private double quantity;


        private int materialSemiID1;
        private double quantityPerSet1;     
        
        private int materialSemiID2;
        private double quantityPerSet2;
      
        private int materialSemiID3;
        private double quantityPerSet3;      

        private string remarks;


        public GCGBCommandCollection()
            : this(0, 0, 0, 0, 0, 0, 0, 0, "")
        {
        }

        public GCGBCommandCollection(int materialSetID, double quantity, int materialSemiID1, double quantityPerSet1, int materialSemiID2, double quantityPerSet2, int materialSemiID3, double quantityPerSet3, string remarks)
        {
            GlobalDefaultValue.Apply(this);

            this.MaterialSetID = materialSetID;
            this.Quantity = quantity;

            this.MaterialSemiID1 = materialSemiID1;
            this.QuantityPerSet1 = quantityPerSet1;            

            this.MaterialSemiID2 = materialSemiID2;
            this.QuantityPerSet2 = quantityPerSet2;

            this.MaterialSemiID3 = materialSemiID3;
            this.QuantityPerSet3 = quantityPerSet3;

            this.Remarks = remarks;
        }


        #region Properties

        [DefaultValue(0)]
        public int MaterialSetID
        {
            get { return this.materialSetID; }
            set { ApplyPropertyChange<GCGBCommandCollection, int>(ref this.materialSetID, o => o.MaterialSetID, value); }
        }


        [DefaultValue(0)]
        public double Quantity
        {
            get { return this.quantity; }
            set {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBCommandCollection, double>(ref this.quantity, o => o.Quantity, value); }
        }




        [DefaultValue(0)]
        public int MaterialSemiID1
        {
            get { return this.materialSemiID1; }
            set { ApplyPropertyChange<GCGBCommandCollection, int>(ref this.materialSemiID1, o => o.MaterialSemiID1, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet1
        {
            get { return this.quantityPerSet1; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBCommandCollection, double>(ref this.quantityPerSet1, o => o.QuantityPerSet1, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi1
        {
            get { return this.Quantity * this.QuantityPerSet1; }            
        }       
     

        [DefaultValue(0)]
        public int MaterialSemiID2
        {
            get { return this.materialSemiID2; }
            set { ApplyPropertyChange<GCGBCommandCollection, int>(ref this.materialSemiID2, o => o.MaterialSemiID2, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet2
        {
            get { return this.quantityPerSet2; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBCommandCollection, double>(ref this.quantityPerSet2, o => o.QuantityPerSet2, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi2
        {
            get { return this.Quantity * this.QuantityPerSet2; }            
        }


        [DefaultValue(0)]
        public int MaterialSemiID3
        {
            get { return this.materialSemiID3; }
            set { ApplyPropertyChange<GCGBCommandCollection, int>(ref this.materialSemiID3, o => o.MaterialSemiID3, value); }
        }

        [DefaultValue(0)]
        public double QuantityPerSet3
        {
            get { return this.quantityPerSet3; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBCommandCollection, double>(ref this.quantityPerSet3, o => o.QuantityPerSet3, value);
            }
        }

        [DefaultValue(0)]
        public double QuantitySemi3
        {
            get { return this.Quantity * this.QuantityPerSet3; }        
        } 


        [DefaultValue("")]
        public string Remarks
        {
            get { return this.remarks; }
            set { ApplyPropertyChange<GCGBCommandCollection, string>(ref this.remarks, o => o.Remarks, value); }
        }

        #endregion

        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("MaterialSetID", "Please fill a material set.", delegate { return !(this.Quantity > 0 && this.MaterialSetID <= 0); }));
            validationRules.Add(new SimpleValidationRule("MaterialSemiID1", "Please fill a material semi.", delegate { return !(this.Quantity > 0 && this.MaterialSemiID1 <= 0); }));
            
            return validationRules;
        }
    }
}
